<template>
  <el-cascader
    v-model="current_field"
    clearable
    expand-trigger="tigger"
    :options="cascaderOptions"
    :placeholder="$util.getDefValue(current_args.placeholder, '请选择')"
    :props="props"
    :disabled="disabledValue"
    collapse-tags
    @change="$emit('update:value', current_field)"
  />
</template>
<script>
export default {
  props: {
    value: {
      type: String,
      default: ''
    },
    args: {
      type: Object,
      required: true,
      default: _ => {
        return {};
      }
    },
    options: {
      type: Array,
      default: _ => {
        return [];
      }
    }
  },
  data() {
    return {
      current_field: this.value,
      current_args: this.args
    };
  },
  computed: {
    disabledValue() {
      if (this.current_args.disabled == '1') {
        return true;
      }

      return null;
    },
    tigger() {
      return this.current_args.tigger ? this.current_args.tigger : 'click';
    },
    cascaderOptions() {
      if (this.options.length > 0) {
        return this.options;
      }
      return [];
    },
    props() {
      const props = {};
      if (this.args.multiple) {
        props.multiple = true;
      }
      return props;
    }
  },
  watch: {
    value: {
      handler(now, old) {
        this.current_field = now;
      }
    }
  }
};
</script>
